#ifndef _TIMER_H
#define _TIMER_H


enum {TIMER_ON, TIMER_OFF, TIMER_FREE};

typedef void (*CALLBACK)(PTR);

typedef struct tTIMER
{
    struct tTIMER *Prev;		// 4 bytes
    struct tTIMER *Next;		// 4 bytes
    U32 state; 
    U32 timeRemaining;		// Remaining Time in msec
    CALLBACK timerCb;		// Timer's callback function
    void *Param;			// Generic pointer to data which may be used by the action routine
} TIMERINFO, *PTIMERINFO;

typedef struct tagTIMERCONTEXT {
    SYS_lock_t lock;
    U32 resolution;
    PTIMERINFO pTimerList; //header
    void* pTimerMemory;
} TIMERCONTEXT,*PTIMERCONTEXT;

extern void TIMERS_proc(PTIMERCONTEXT pTimerContext);
extern TIMERINFO* TIMERS_start_timer(PTIMERCONTEXT pTimerContext, U32 msTime, CALLBACK cb, void *Param);
extern void TIMERS_clear_timer(PTIMERCONTEXT pTimerContext,PTIMERINFO pTimerInfo);
extern void TIMERS_restart_timer(PTIMERINFO pTimerInfo, U32 msTime);
extern  RESULT TIMERS_init(PTIMERCONTEXT pTimerContext,void* pTimerMemory,U32 resolution );
extern RESULT TIMERS_destory(PTIMERCONTEXT pTimerContext );

#endif

